package listbyorder.access101_200.test179;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/15 9:54
 */
public class Solution1 {

    // 方法一： 将数字转化为字符串进行求解
    public String largestNumber(int[] nums) {
        String[] strs = new String[nums.length];

        for (int i = 0; i < nums.length; i++) {
            strs[i] = nums[i] + "";
        }

        Arrays.sort(strs, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                String order1 = o1 + o2;
                String order2 = o2 + o1;
                return order2.compareTo(order1);
            }
        });

        StringBuilder sb = new StringBuilder();

        for (String str : strs) {
            sb.append(str);
        }
        String ans = sb.toString();
        return ans.charAt(0) == '0' ? "0" : ans;
    }

}
